function disableRegisterForm()
{
	var registerform = document.getElementById('registerform');
	var count = registerform.elements.length;
	for (i=0; i<count; i++) 
	  {
	var element = registerform.elements[i]; 
	if (registerform.checkagree.checked == false) 
		{ 
		if (element.type == "text" || element.type == "submit" || element.type == "password")
		{ element.disabled=true; } 
		} 
	else 
		{ element.disabled=false; }
	  }
}

function callXMLHTTP(url, pageElement, waitingMessage, errorMessage){
	pageElement.innerHTML = waitingMessage;
	try{
		req = new XMLHttpRequest();
	}catch(e){
		try{
			req = new ActiveXObject('Msxml2.XMLHTTP');
		}catch(e){
			try{
				req = new ActiveXObject('Microsft.XMLHTTP');
			}catch(e){
				req = false;
			}
		}
	}
	req.onreadystatechange = function(){responseXMLHTTP(pageElement, errorMessage);};
	req.open("GET", url, true);
	req.send(null);
}

function responseXMLHTTP(pageElement, errorMessage){
	var output = '';
	if(req.readyState == 4){
		if(req.status == 200){ 
			output = req.responseText;
			pageElement.innerHTML = output; 
		} else {
			pageElement.innerHTML = errorMessage+"\n"+req.responseText; 
		}
	}
}

function initTabControl(tabcontrolid, ajaxtargetpanel){
	var e, i = 0, tabcontrol = document.getElementById(tabcontrolid);
	while (e = tabcontrol.getElementsByTagName('DIV') [i++]) {
		if (e.className.indexOf('on') > -1 || e.className.indexOf('off') > -1) {
		e.onclick = function () {
				var getEls = tabcontrol.getElementsByTagName('DIV');
				for (var z=0; z<getEls.length; z++) {
					getEls[z].className = getEls[z].className.replace('show', 'hide');
					getEls[z].className = (getEls[z].className.indexOf("ajax_tab") > -1) ? 
						getEls[z].className.replace('on ajax_tab', 'off ajax_tab') : getEls[z].className.replace('on', 'off');
				}
				var isAjaxTab = this.className.indexOf("ajax_tab") > -1;
				this.className = (isAjaxTab) ? 'on ajax_tab' : 'on';
				var tabpage = document.getElementById((isAjaxTab) ? ajaxtargetpanel : this.getAttribute('id')+'_panel');
				tabpage.className = "show";
				
				var targeturl = '#';
				if (isAjaxTab){
					for (var i=0; i < tabbedpages.length; i++){
						if(tabbedpages[i][0] == this.getAttribute('id')){
							targeturl = tabbedpages[i][1];
							break;
						}
					}
					callXMLHTTP(targeturl, tabpage, '<img src="images/loading.gif" alt="Loading." style="margin-bottom: 10px;"/>', 'Error: ');
				}
			}
		}
	}
}

function acceptAuction(auction_id) {
	callXMLHTTP('auction_op.php?op=accept&id='+auction_id, document.getElementById('usertabs_ajaxpanel'), '<img src="images/loading.gif" alt="Loading." style="margin-bottom: 10px;"/>', 'Error: ');
}

function refuseAuction(auction_id) {
	callXMLHTTP('auction_op.php?op=refuse&id='+auction_id, document.getElementById('usertabs_ajaxpanel'), '<img src="images/loading.gif" alt="Loading." style="margin-bottom: 10px;"/>', 'Error: ');
}

function payAuction(auction_id) {
	callXMLHTTP('auction_op.php?op=pay&id='+auction_id, document.getElementById('usertabs_ajaxpanel'), '<img src="images/loading.gif" alt="Loading." style="margin-bottom: 10px;"/>', 'Error: ');
}

Array.prototype.contains = function (element) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == element) {
			return true;
		}
	}
	return false;
}

/* The following found at: 
 http://simonwillison.net/2004/May/26/addLoadEvent */

function addLoadEvent(newfunc) {
	var oldfunc = window.onload;
	if(typeof window.onload != 'function')
		window.onload = newfunc;
	else{
		if(oldfunc)
			oldfunc();
		window.onload = newfunc;
	}
}

/* made by altering the above function :) */
function addUnloadEvent(newfunc) {
	var oldfunc = window.onunload;
	if(typeof window.onunload != 'function')
		window.onunload = newfunc;
	else{
		if(oldfunc)
			oldfunc();
		window.onunload = newfunc;
	}
}

addLoadEvent(function(){clockInit(clockLocalStartTime, clockServerStartTime);});
addLoadEvent(clockOnLoad);
addLoadEvent(function(){if(!NiftyCheck())return;
	Rounded("div#nifty div","top","transparent","#7BBB15","border #C0C0C0");
	Rounded("div#nifty div","bottom","transparent","#F0F0E7","border #C0C0C0");});
addUnloadEvent(function(){clockOnUnload();});
